﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="LogonModeUI.aspx.vb" Inherits="Map.LogonModeUI" %>

<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>登录模式设置</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    <link rel="stylesheet" type="text/css" href="/_nav/menu.css">
    <link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
    <link rel="stylesheet" type="text/css" href="/_forms/styles/form.css">
    <link rel="stylesheet" type="text/css" href="/_nav/tabs.css">
    <link rel="stylesheet" type="text/css" href="/_nav/nav.css">
    <link rel="stylesheet" type="text/css" href="/_common/styles/select.css">
    <style>
        div.list
        {
            float: left;
        }
    </style>

    <script language="javascript" src="/_common/scripts/global.js"></script>

    <script language="javascript" src="/_common/scripts/json-mini.js"></script>

    <script language="javascript" src="/_controls/settings.aspx"></script>

    <script language="javascript" src="/_controls/util/util.js"></script>

    <script language="javascript" src="/_controls/lookup/map_lookup.js"></script>

    <script language="javascript" src="/_nav/menu.js"></script>

    <script language="javascript" src="/_forms/FormBase.js"></script>

    <script src="/_controls/util/util.vbs" language="vbscript"></script>
    
    <script language="javascript">
 	    //在线帮助文件
		var _MyHelpfile = "/help/yxsz.htm";

        var urlSetting = "/LogonModeSetting.aspx";
        var hasDSS, objHasDSSSite, DSSSite, DSSUrl;

        function checkMode(obj) {
            var tbCookie = document.getElementById("tbCookieSetting");
            var tbAD = document.getElementById("tbADSetting");
            switch (obj) {
                case "AD":
                    tbCookie.style.display = "none";
                    tbAD.style.display = "";
                    break;
                case "Cookie":
                    tbCookie.style.display = "";
                    tbAD.style.display = "none";
                    break;
                case "Form":
                    tbCookie.style.display = "none";
                    tbAD.style.display = "none";
                    break;
            }
        }

        function getRasKey(isCreate) {
            var sRtn = XmlHttpRequest(urlSetting, "GetRSAKey", "isCreate=" + isCreate);
            if (sRtn) {
                var obj = eval('(' + sRtn + ')');
                if (obj.result) {
                    document.getElementById("txtPublicKey").value = obj.PublicKey;
                    document.getElementById("txtPrivateKey").value = obj.PrivateKey;
                }
                else {
                    document.getElementById("txtPrivateKey").value = "";
                    document.getElementById("txtPublicKey").value = "";
                }
            }

        }

        function doSetup() {
            var objPubKey = document.getElementById("txtPublicKey"), objPrvKey = document.getElementById("txtPrivateKey");
            if (objPubKey.value == "") {
                alert("公钥不能为空！");
                objPubKey.focus();
                return false;
            }
            if (objPrvKey.value == "") {
                alert("私钥不能为空！");
                objPrvKey.focus();
                return false;
            }

            var mySet = { "LOGON_MODE": "", "DomainName": "", "PrivateKey": "", "PublicKey": "", "IIS_PASS": "" };
            //登录模式
            if (document.getElementById("appForm_AD").checked) { mySet.LOGON_MODE = "AD" }
            else if (document.getElementById("appForm_Cookie").checked) { mySet.LOGON_MODE = "Cookie" }
            else { mySet.LOGON_MODE = "Form" }

            //AD集成相关设置
            mySet.IIS_PASS = document.getElementById("appForm_IIS_PASS1").checked ? "1" : "0";

            //Cookie集成相关设置
            mySet.DomainName = document.getElementById("txtDomainName").value;
            mySet.PublicKey = objPubKey.value;
            mySet.PrivateKey = objPrvKey.value;

            var sdata = mySet.toJSONString();
            var url = urlSetting + "?myset=" + vbEscape(sdata);
            var sRtn = XmlHttpRequest(url, "SaveSetting");
            if (isSucc(sRtn)) {
                if (hasDSS == "1") {
                    if (DSSSite == "") {
                        alert("DSS 站点地址未设置，不能同步设置！");
                        return false;
                    }

                    if (objHasDSSSite.value != "1") {
                        alert("DSS 站点的设置页面无法访问，不能同步设置！");
                        return false;
                    }
                    doSetupOtherSite(sdata);
                }
                else {
                    alert("保存成功"); 
                }
            }
        }

        function isSucc(sRtn) {
            if (sRtn) {
                var obj = eval('(' + sRtn + ')');
                if (obj.result) { return true; }
                else {
                    alert("设置 ERP 站点不成功:" + obj.message);
                    return false;
                }
            }
            return false;
        }
        function isSONPSucc(sRtn) {
            if (sRtn) {
                var obj = eval('(' + sRtn.replace(/\\/g,"\\\\") + ')');
                if (obj.result) { alert("保存成功"); return true; }
                else {
                    alert("同步设置 DSS 站点不成功:" + obj.message);
                    return false;
                }
            }
            return false;
        }

        function doSetupOtherSite(sdata) {
            var id = "js_dsssite", url = DSSUrl + "&p_businessType=SaveSetting&ReturnFunction=isSONPSucc&myset=" + vbEscape(sdata);
            CallJSONPServer(id, url);
        }


        function checkDomain() {
            var txtDomain = document.getElementById("txtDomainName");
            //取当前域名
            var sRtn = XmlHttpRequest(urlSetting, "GetDomain", "");
            if (sRtn) {
                var obj = eval('(' + sRtn + ')');
                if (obj.result) {
                    txtDomain.value = obj.DomainName;
                }
                else { txtDomain.value = "" }
            }
        }

        window.attachEvent("onload", function() {
            appForm._bAlert = false;

            //DSS设点相关设置值
            objHasDSSSite = document.getElementById("txtHasDSSSite");
            hasDSS = document.getElementById("txtHasDSS").value;
            DSSSite = document.getElementById("txtDSSSite").value;
            var usercode = document.getElementById("txtUserCode").value;
            var password = document.getElementById("txtPassWord").value;
            DSSUrl = DSSSite + urlSetting + "?usercode=" + usercode + "&password=" + password;

            //选择Cookie时，显示Cookie相关设置，否则隐藏
            if (document.getElementById("appForm_AD").checked) {
                checkMode("AD");
            } else
                if (document.getElementById("appForm_Cookie").checked) {
                checkMode("Cookie");
            } else
            { checkMode("Form"); }

            if (hasDSS == "1") {
                document.getElementById("lbDSSMessage").innerHTML = "保存将同步更新 DSS 站点设置！"
                checkDSSSite();
            }
        })

        function checkDSSSite(sRtn) {
            if (sRtn) {
                //检测成功返回结果后，设置
                var obj = eval('(' + sRtn + ')');
                if (obj.result) { objHasDSSSite.value = "1" }
            }
            else {
                var id = "js_dsssite", url = DSSUrl + "&p_businessType=checkDSSSite&ReturnFunction=checkDSSSite";
                CallJSONPServer(id, url);
            }
        }

        function CallJSONPServer(id, url) {                                 // 调用JSONP服务器，url为请求服务器地址
            var oldScript = document.getElementById(id);       // 如果页面中注册了调用的服务器，则重新调用
            if (oldScript) {
                oldScript.setAttribute("src", url);
                return;
            }
            var script = document.createElement("script");       // 如果未注册该服务器，则注册并请求之
            script.setAttribute("type", "text/javascript");
            script.setAttribute("src", url);
            script.setAttribute("id", id);
            script.setAttribute("language", "ecmascript");
            document.appendChild(script);
        }

    </script>

</head>
<body style="background-color: #fffbff">
    <form class="map2" id="appForm" method="post" runat="server">
    <input type="hidden" id="txtUserCode" name="txtUserCode" value="" runat="server" />
    <input type="hidden" id="txtPassWord" name="txtPassWord" value="" runat="server" />
    <input type="hidden" id="txtHasDSS" name="txtHasDSS" value="" runat="server" />
    <input type="hidden" id="txtDSSSite" name="txtDSSSite" value="" runat="server" />
    <input type="hidden" id="txtHasDSSSite" name="txtHasDSSSite" value="" />
    <table height="100%" cellspacing="0" cellpadding="0" width="100%">
        <tr>
            <td>
                <table height="100%" cellspacing="0" cellpadding="0" width="100%">
                    <tr>
                        <td class="main" style="padding-bottom: 0px">
                            <table style="table-layout: fixed; vertical-align: text-bottom" height="100%" cellspacing="0"
                                cellpadding="3" width="100%">
                                <tbody>
                                    <tr height="20">
                                        <td class="sec bar" colspan="1">
                                            <font style="font-weight: bold; font-size: 10pt; color: black">集成登录模式设置</font>
                                        </td>
                                    </tr>
                                    <tr height="5">
                                        <td colspan="2">
                                        </td>
                                    </tr>
                                    <tr height="35">
                                        <td class="wizbox1">
                                            <table width="100%" cellspacing="3" cellpadding="3" style="table-layout: fixed;"
                                                id="Section1">
                                                <col width="100">
                                                <col>
                                                <tr>
                                                    <td class="req">
                                                        登录模式
                                                    </td>
                                                    <td>
                                                        <input class="rad3" type="hidden" name="LogonMode" value="" readonly ro="0" req="0">
                                                        <table cellpadding="0" cellspacing="0">
                                                            <tr>
                                                                <td>
                                                                    <input type="radio" class="rad2" id="appForm_AD" name="appForm_LogonMode" value="AD"
                                                                        runat="server" onclick="checkMode('AD')">
                                                                </td>
                                                                <td class="radioLabel">
                                                                    <label for="appForm_AD">
                                                                        AD集成登录</label>
                                                                </td>
                                                                <td>
                                                                    <input type="radio" class="rad2" id="appForm_Cookie" name="appForm_LogonMode" value="Cookie"
                                                                        runat="server" onclick="checkMode('Cookie')">
                                                                </td>
                                                                <td class="radioLabel">
                                                                    <label for="appForm_Cookie">
                                                                        Cookie集成登录</label>
                                                                </td>
                                                                <td>
                                                                    <input type="radio" class="rad2" id="appForm_Form" name="appForm_LogonMode" value="Form"
                                                                        runat="server" onclick="checkMode('Form')">
                                                                </td>
                                                                <td class="radioLabel">
                                                                    <label for="appForm_Form">
                                                                        普通登录</label>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </tbody>
                                <tbody id="tbADSetting" style="display: none">
                                    <tr height="5">
                                        <td colspan="2">
                                        </td>
                                    </tr>
                                    <tr height="20">
                                        <td class="sec bar" colspan="1">
                                            <font style="font-weight: bold; font-size: 10pt; color: black">AD集成登录相关设置</font>
                                        </td>
                                    </tr>
                                    <tr height="5">
                                        <td colspan="2">
                                        </td>
                                    </tr>
                                    <tr height="120">
                                        <td class="wizbox1">
                                            <table width="100%" cellspacing="3" cellpadding="3" style="table-layout: fixed;"
                                                id="Table2">
                                                <col width="90" valign="top">
                                                <col>
                                                <tr>
                                                    <td class="req">
                                                        验证模式
                                                    </td>
                                                    <td>
                                                        <input class="rad3" type="hidden" name="IIS_PASS" value="" readonly ro="0" req="0">
                                                        <table cellpadding="0" cellspacing="0">
                                                            <tr>
                                                                <td>
                                                                    <input type="radio" class="rad2" id="appForm_IIS_PASS1" name="appForm_IIS_PASS" value="1"
                                                                        runat="server">
                                                                </td>
                                                                <td class="radioLabel">
                                                                    <label for="appForm_IIS_PASS1">
                                                                        AD验证</label>
                                                                </td>
                                                                <td>
                                                                    <input type="radio" class="rad2" id="appForm_IIS_PASS0" name="appForm_IIS_PASS" value="0"
                                                                        runat="server">
                                                                </td>
                                                                <td class="radioLabel">
                                                                    <label for="appForm_IIS_PASS0">
                                                                        AD验证+用户登录验证</label>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                                <tr height="50">
                                                    <td>
                                                    </td>
                                                    <td>
                                                        AD验证&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;：只要能通过AD验证，并且系统用户列表中存在该用户，就认为验证通过，可以进入系统。
                                                        <br />
                                                        AD验证+用户登录验证：为二重验证，首先要通过AD验证，然后还需要进行ERP系统登录后，方可进入系统。<br />
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </tbody>
                                <tbody id="tbCookieSetting" style="display: none">
                                    <tr height="5">
                                        <td colspan="2">
                                        </td>
                                    </tr>
                                    <tr height="20">
                                        <td class="sec bar" colspan="1">
                                            <font style="font-weight: bold; font-size: 10pt; color: black">Cookie集成登录相关设置</font>
                                        </td>
                                    </tr>
                                    <tr height="5">
                                        <td colspan="2">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="wizbox1">
                                            <table width="100%" cellspacing="3" cellpadding="3" style="table-layout: fixed;"
                                                id="Table1">
                                                <col width="90" valign="top">
                                                <col>
                                                <tr>
                                                    <td class="req">
                                                        域
                                                    </td>
                                                    <td>
                                                        <table width="100%">
                                                            <tr>
                                                                <td>
                                                                    <input type="text" class="txt" id="txtDomainName" name="txtDomainName" runat="server"
                                                                        maxlength="50" />
                                                                </td>
                                                                <td width="80px">
                                                                    <button style="width: 70px" onclick="checkDomain();" type="button">
                                                                        获取</button>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                                <tr height="120">
                                                    <td>
                                                    </td>
                                                    <td valign="top">
                                                        Cookie 集成方式下，不允许使用 IP 访问，各集成系统必须配置相同域。<br />
                                                        <b>配置方法：</b><br />
                                                        1、各系统子域名级别相同时，“域”值可为空。<br />
                                                        例如: ERP 通过 http://erp.my.com 访问，DSS 通过 http://dss.my.com 访问。<br />
                                                        <br />
                                                        2、各系统子域名级别不相同时，“域”值必须设置。<br />
                                                        例如: ERP 通过 http://erp.site1.my.com 访问，DSS 通过 http://dss.my.com 访问时，“域”设置为“my.com”。<br />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="req">
                                                        私钥
                                                    </td>
                                                    <td>
                                                        <textarea id="txtPrivateKey" name="txtPrivateKey" rows="4" maxlength="1000" runat="server"></textarea>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="req">
                                                        公钥
                                                    </td>
                                                    <td>
                                                        <textarea id="txtPublicKey" name="txtPublicKey" rows="4" maxlength="500" runat="server"></textarea>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="req">
                                                    </td>
                                                    <td>
                                                        <table cellpadding="0" cellspacing="0" width="100%">
                                                            <tr>
                                                                Cookie 用户凭证使用 RSA 密钥签名防止伪造。系统出厂时已有默认 RSA 密钥对，为安全起见，建议设置新的密钥对。<td>
                                                                </td>
                                                                <td align="right">
                                                                    <button style="width: 100px" onclick="getRasKey(true);" type="button">
                                                                        生成新密钥对</button>&nbsp;
                                                                    <button style="width: 70px" onclick="getRasKey(false);" type="button">
                                                                        还原</button>&nbsp;
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr height="5">
                                        <td colspan="1">
                                        </td>
                                    </tr>
                                </tbody>
                                <tbody>
                                    <tr height="10">
                                        <td colspan="1">
                                        </td>
                                    </tr>
                                    <tr height="30">
                                        <td>
                                            <table width="100%">
                                                <tr>
                                                    <td>
                                                        <label id="lbDSSMessage" name="lbDSSMessage">
                                                        </label>
                                                    </td>
                                                    <td align="right">
                                                        <button id="btnExec" onclick="doSetup();" name="btnExec" type="button">
                                                            保存</button>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr height="20">
                                        <td colspan="2">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="color: red" colspan="2">
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        </TBODY></table>
    </form>
    <form name="appForm_FormSubmit" method="post">
    <input type="hidden" name="mode" value="1">
    <input type="hidden" name="mapFormSubmitXml">
    <input type="hidden" name="mapFormSubmitMode">
    <input type="hidden" name="mapFormSubmitParam" value="">
    </form>
</body>
</html>
